package jannex.sql;

import jannex.mapping.ResultSetHandler;
import jannex.sql.extensions.TypedPreparedStatementImpl;
import jannex.sql.extensions.TypedResultSetImpl;

import java.util.Map;

@SuppressWarnings("unchecked")
public class TypedQuery<E> extends Query {

    private final ResultSetHandler<E> handler;

    public TypedQuery(Query builder, ResultSetHandler<E> handler) {
        super(builder);
        this.handler = handler;
    }

    public Fetcher<E> fetch(Object... arguments) {
        return super.fetch(handler, arguments);
    }

    @Override
    public TypedQuery<E> set(Object object) {
        super.set(object);
        return this;
    }

    @Override
    public TypedQuery<E> setFrom(Object object) {
        super.setFrom(object);
        return this;
    }

    @Override
    public TypedQuery<E> set(String key, Object object) {
        super.set(key, object);
        return this;
    }

    @Override
    public TypedQuery<E> setAll(Iterable<Object> list) {
        super.setAll(list);
        return this;
    }

    @Override
    public TypedQuery<E> setAll(Object... objects) {
        super.setAll(objects);
        return this;
    }

    @Override
    public TypedQuery<E> setAll(Map<String, Object> map) {
        super.setAll(map);
        return this;
    }

    @Override
    public TypedPreparedStatement<E> build(Object... arguments) {
        return new TypedPreparedStatementImpl<>(super.build(arguments), jannex, handler);
    }

    @Override
    public TypedResultSet<E> resultSet(Object... arguments) {
        return new TypedResultSetImpl<>(super.resultSet(arguments), jannex, handler);
    }

    @Override
    public TypedQuery<E> setResultSetType(int resultSetType) {
        super.setResultSetType(resultSetType);
        return this;
    }

    @Override
    public TypedQuery<E> setResultSetConcurrency(int resultSetConcurrency) {
        super.setResultSetConcurrency(resultSetConcurrency);
        return this;
    }

    @Override
    public TypedQuery<E> setResultSetHoldability(int resultSetHoldability) {
        super.setResultSetHoldability(resultSetHoldability);
        return this;
    }

    @Override
    public TypedQuery<E> setFetchSize(int fetchSize) {
        super.setFetchSize(fetchSize);
        return this;
    }

    @Override
    public TypedQuery<E> setMaxRows(int maxRows) {
        super.setMaxRows(maxRows);
        return this;
    }

    @Override
    public TypedQuery<E> setFetchDirection(int fetchDirection) {
        super.setFetchDirection(fetchDirection);
        return this;
    }

    @Override
    public TypedQuery<E> setPoolable(boolean poolable) {
        super.setPoolable(poolable);
        return this;
    }

    @Override
    public TypedQuery<E> setQueryTimeout(int queryTimeout) {
        super.setQueryTimeout(queryTimeout);
        return this;
    }

}
